package com.test.daily.leetcode.y2021.m11.day1126;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2021/11/26 下午 11:27
 * @version: 1.0
 */
public class Code01_SearchBST {
    public static void main(String[] args) {
        TreeNode tr1 = new TreeNode(1);
        TreeNode tr2 = new TreeNode(2);
        TreeNode tr3 = new TreeNode(3);
        TreeNode tr4 = new TreeNode(4);
        TreeNode tr5 = new TreeNode(5);
        tr1.left = tr2;
        tr1.right = tr3;
        tr2.left = tr4;
        tr2.right = tr5;
        Code01_SearchBST cs = new Code01_SearchBST();
        cs.searchBST(tr1, 4);
        int[][] a = new int[7][10];
        System.out.println("有几行?" + a.length);
    }
    public TreeNode searchBST(TreeNode root, int val) {
        while(root != null){
            if(root.val == val){
                return root;
            }else if(root.val>val){
                root = root.left;
            }else{
                root = root.right;
            }
        }
        return null;
    }

    /**
     * Definition for a binary tree node.
     *      */
    public static class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
       this.val = val;
       this.left = left;
       this.right = right;
       }
    }

}
